{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第七次人口普查数据分析可视化项目介绍\n",
    "## 项目人：钟莉\n",
    "## 时间：2021/07/01\n",
    "## 数据源：\n",
    "> [国家统计局](http://www.stats.gov.cn/tjsj/tjgb/rkpcgb/)\n",
    "- 由于第七次人口普查数据并未完全公布，只发布了8个全国人口普查公报。有表格数据的只有4个公报。\n",
    "- 因此，我在以下4个公报中，抓取了6个表格数据，并导出csv文件到data文件夹中。\n",
    ">>1. [第七次全国人口普查公报（第三号）](http://www.stats.gov.cn/tjsj/tjgb/rkpcgb/qgrkpcgb/202106/t20210628_1818822.html)\n",
    ">>2. [第七次全国人口普查公报（第四号）](http://www.stats.gov.cn/tjsj/tjgb/rkpcgb/qgrkpcgb/202106/t20210628_1818823.html)\n",
    ">>3. [第七次全国人口普查公报（第五号）](http://www.stats.gov.cn/tjsj/tjgb/rkpcgb/qgrkpcgb/202106/t20210628_1818824.html)\n",
    ">>4. [第七次全国人口普查公报（第六号）](http://www.stats.gov.cn/tjsj/tjgb/rkpcgb/qgrkpcgb/202106/t20210628_1818825.html)\n",
    "\n",
    "## 数据分析：\n",
    "### 数据抓取：\n",
    "- 利用pandas库中的read_html方法快速抓取网页中的表格型数据\n",
    "- 使用DataFrame对象中的loc属性和iloc属性进行数据抽取、数据的增加、修改和删除、索引设置，以获得最有价值、整洁的数据    \n",
    "\n",
    "### 可视化\n",
    "- 使用pyecharts进行数据可视化，共制作了以下9个可视化图表    \n",
    "\n",
    ">1. 全国人口分布_地图\n",
    ">2. 中国十年增长人数_折线图\n",
    ">3. 各地区人口性别构成_地图\n",
    ">4. 全国人口年龄占比_饼状图\n",
    ">5. 各地区每10万人口中拥有的各类受教育程度人数_地图\n",
    ">6. 北上广三地大学学历人数比较图_柱状图\n",
    ">7. 老龄化程度对比图_柱状图、折线图\n",
    ">8. 新生一代对比图_柱状图、折线图\n",
    ">9. 各地区15岁及以上人口平均受教育年限对比图\n",
    "## 目标\n",
    "- 人口问题始终是我国面临的全局性、长期性、战略性问题，我们必须要准确了解当前人口变化的趋势性特征。\n",
    "- 加强人口发展的前瞻性、战略性研究，为推动高质量发展、有针对性地制定人口相关战略和政策、促进人口长期均衡发展提供强有力的统计信息支持。\n",
    "- 调整完善人口政策，推动人口结构优化，促进人口素质提升。\n",
    "- 同时，为未来行业发展提供新方向，比如：老龄化问题严重，未来应更加注重老年人健康医疗行业等。      \n",
    "\n",
    "## 注：本次项目共有两个ipynb文档，此为数据分析可视化.ipynb文档"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import plotly.express as px\n",
    "%matplotlib inline\n",
    "sns.set(font='Microsoft YaHei',palette='GnBu_r',font_scale=1.3)\n",
    "import matplotlib\n",
    "matplotlib.rc('figure',figsize =(20,8))\n",
    "from warnings import filterwarnings\n",
    "filterwarnings('ignore')\n",
    "\n",
    "import pandas as pd\n",
    "from pyecharts.charts import Map\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts.charts import Line\n",
    "from pyecharts.charts import Grid\n",
    "from pyecharts.charts import Pie\n",
    "from pyecharts.charts import Scatter\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Page, WordCloud\n",
    "from pyecharts.globals import SymbolType\n",
    "from pyecharts.globals import ThemeType, CurrentConfig\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "from pyecharts.globals import CurrentConfig, NotebookType\n",
    "CurrentConfig.NOTEBOOK_TYPE = NotebookType.NTERACT\n",
    "\n",
    "from pyecharts.commons.utils import JsCode"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 全国人口分布_地图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "population = pd.read_csv('data/各地区人口构成数据.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删掉全国的数据\n",
    "population.drop(index=[0],inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\1\\\\Desktop\\\\第七次人口普查数据\\\\html\\\\全国人口分布地图.html'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_data = population['地区'].tolist()\n",
    "y_data = population['人口数(人)'].tolist()\n",
    "\n",
    "m = Map()\n",
    "m.add('',[list(z) for z in zip(x_data,y_data)],maptype = 'china',is_map_symbol_show=False)\n",
    "m.set_series_opts(label_opts = opts.LabelOpts(is_show=True))\n",
    "m.set_global_opts(title_opts = opts.TitleOpts(title = '全国人口分布地图',\n",
    "                                              subtitle = '此为全国常住人口的有关数据 \\n数据表明：广东省的常住人口数量最多，人口密度由黑河—腾冲线划分开，黑河—腾冲线以东占了全国96%的人口',),\n",
    "visualmap_opts = opts.VisualMapOpts(min_=population['人口数(人)'].min(),max_=population['人口数(人)'].max(),\n",
    "range_color=['#C2E7C0','#61BDCD','#0D6DAE']))\n",
    "m.render('html/全国人口分布地图.html')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 中国十年增长人数_折线图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>人口数(人)</th>\n",
       "      <th>2020年比重(%)</th>\n",
       "      <th>2010年比重(%)</th>\n",
       "      <th>地区</th>\n",
       "      <th>增长比例</th>\n",
       "      <th>2010年人数</th>\n",
       "      <th>10年增长人数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>19</td>\n",
       "      <td>126012510</td>\n",
       "      <td>8.93</td>\n",
       "      <td>7.79</td>\n",
       "      <td>广东</td>\n",
       "      <td>1.14</td>\n",
       "      <td>1.038260e+08</td>\n",
       "      <td>2.218654e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>11</td>\n",
       "      <td>64567588</td>\n",
       "      <td>4.57</td>\n",
       "      <td>4.06</td>\n",
       "      <td>浙江</td>\n",
       "      <td>0.51</td>\n",
       "      <td>5.411212e+07</td>\n",
       "      <td>1.045547e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>84748016</td>\n",
       "      <td>6.00</td>\n",
       "      <td>5.87</td>\n",
       "      <td>江苏</td>\n",
       "      <td>0.13</td>\n",
       "      <td>7.823600e+07</td>\n",
       "      <td>6.512018e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>15</td>\n",
       "      <td>101527453</td>\n",
       "      <td>7.19</td>\n",
       "      <td>7.15</td>\n",
       "      <td>山东</td>\n",
       "      <td>0.04</td>\n",
       "      <td>9.529598e+07</td>\n",
       "      <td>6.231476e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>16</td>\n",
       "      <td>99365519</td>\n",
       "      <td>7.04</td>\n",
       "      <td>7.02</td>\n",
       "      <td>河南</td>\n",
       "      <td>0.02</td>\n",
       "      <td>9.356332e+07</td>\n",
       "      <td>5.802196e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>13</td>\n",
       "      <td>41540086</td>\n",
       "      <td>2.94</td>\n",
       "      <td>2.75</td>\n",
       "      <td>福建</td>\n",
       "      <td>0.19</td>\n",
       "      <td>3.665230e+07</td>\n",
       "      <td>4.887787e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>20</td>\n",
       "      <td>50126804</td>\n",
       "      <td>3.55</td>\n",
       "      <td>3.44</td>\n",
       "      <td>广西</td>\n",
       "      <td>0.11</td>\n",
       "      <td>4.584869e+07</td>\n",
       "      <td>4.278110e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>31</td>\n",
       "      <td>25852345</td>\n",
       "      <td>1.83</td>\n",
       "      <td>1.63</td>\n",
       "      <td>新疆</td>\n",
       "      <td>0.20</td>\n",
       "      <td>2.172482e+07</td>\n",
       "      <td>4.127528e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>24</td>\n",
       "      <td>38562148</td>\n",
       "      <td>2.73</td>\n",
       "      <td>2.59</td>\n",
       "      <td>贵州</td>\n",
       "      <td>0.14</td>\n",
       "      <td>3.451980e+07</td>\n",
       "      <td>4.042346e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>23</td>\n",
       "      <td>83674866</td>\n",
       "      <td>5.93</td>\n",
       "      <td>6.00</td>\n",
       "      <td>四川</td>\n",
       "      <td>-0.07</td>\n",
       "      <td>7.996865e+07</td>\n",
       "      <td>3.706214e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>22</td>\n",
       "      <td>32054159</td>\n",
       "      <td>2.27</td>\n",
       "      <td>2.15</td>\n",
       "      <td>重庆</td>\n",
       "      <td>0.12</td>\n",
       "      <td>2.865543e+07</td>\n",
       "      <td>3.398725e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>74610235</td>\n",
       "      <td>5.28</td>\n",
       "      <td>5.36</td>\n",
       "      <td>河北</td>\n",
       "      <td>-0.08</td>\n",
       "      <td>7.143866e+07</td>\n",
       "      <td>3.171572e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>21893095</td>\n",
       "      <td>1.55</td>\n",
       "      <td>1.46</td>\n",
       "      <td>北京</td>\n",
       "      <td>0.09</td>\n",
       "      <td>1.945904e+07</td>\n",
       "      <td>2.434056e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>27</td>\n",
       "      <td>39528999</td>\n",
       "      <td>2.80</td>\n",
       "      <td>2.79</td>\n",
       "      <td>陕西</td>\n",
       "      <td>0.01</td>\n",
       "      <td>3.718542e+07</td>\n",
       "      <td>2.343576e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>24870895</td>\n",
       "      <td>1.76</td>\n",
       "      <td>1.72</td>\n",
       "      <td>上海</td>\n",
       "      <td>0.04</td>\n",
       "      <td>2.292435e+07</td>\n",
       "      <td>1.946548e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>12</td>\n",
       "      <td>61027171</td>\n",
       "      <td>4.32</td>\n",
       "      <td>4.44</td>\n",
       "      <td>安徽</td>\n",
       "      <td>-0.12</td>\n",
       "      <td>5.917680e+07</td>\n",
       "      <td>1.850368e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>25</td>\n",
       "      <td>47209277</td>\n",
       "      <td>3.34</td>\n",
       "      <td>3.43</td>\n",
       "      <td>云南</td>\n",
       "      <td>-0.09</td>\n",
       "      <td>4.571541e+07</td>\n",
       "      <td>1.493864e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>21</td>\n",
       "      <td>10081232</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.65</td>\n",
       "      <td>海南</td>\n",
       "      <td>0.06</td>\n",
       "      <td>8.663271e+06</td>\n",
       "      <td>1.417961e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>18</td>\n",
       "      <td>66444864</td>\n",
       "      <td>4.71</td>\n",
       "      <td>4.90</td>\n",
       "      <td>湖南</td>\n",
       "      <td>-0.19</td>\n",
       "      <td>6.530773e+07</td>\n",
       "      <td>1.137131e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>30</td>\n",
       "      <td>7202654</td>\n",
       "      <td>0.51</td>\n",
       "      <td>0.47</td>\n",
       "      <td>宁夏</td>\n",
       "      <td>0.04</td>\n",
       "      <td>6.264211e+06</td>\n",
       "      <td>9.384429e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>13866009</td>\n",
       "      <td>0.98</td>\n",
       "      <td>0.97</td>\n",
       "      <td>天津</td>\n",
       "      <td>0.01</td>\n",
       "      <td>1.292827e+07</td>\n",
       "      <td>9.377436e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>17</td>\n",
       "      <td>57752557</td>\n",
       "      <td>4.09</td>\n",
       "      <td>4.27</td>\n",
       "      <td>湖北</td>\n",
       "      <td>-0.18</td>\n",
       "      <td>5.691102e+07</td>\n",
       "      <td>8.415329e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>14</td>\n",
       "      <td>45188635</td>\n",
       "      <td>3.20</td>\n",
       "      <td>3.33</td>\n",
       "      <td>江西</td>\n",
       "      <td>-0.13</td>\n",
       "      <td>4.438260e+07</td>\n",
       "      <td>8.060331e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>26</td>\n",
       "      <td>3648100</td>\n",
       "      <td>0.26</td>\n",
       "      <td>0.22</td>\n",
       "      <td>西藏</td>\n",
       "      <td>0.04</td>\n",
       "      <td>2.932184e+06</td>\n",
       "      <td>7.159161e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>29</td>\n",
       "      <td>5923957</td>\n",
       "      <td>0.42</td>\n",
       "      <td>0.42</td>\n",
       "      <td>青海</td>\n",
       "      <td>0.00</td>\n",
       "      <td>5.597806e+06</td>\n",
       "      <td>3.261514e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>28</td>\n",
       "      <td>25019831</td>\n",
       "      <td>1.77</td>\n",
       "      <td>1.91</td>\n",
       "      <td>甘肃</td>\n",
       "      <td>-0.14</td>\n",
       "      <td>2.545669e+07</td>\n",
       "      <td>-4.368566e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>24049155</td>\n",
       "      <td>1.70</td>\n",
       "      <td>1.84</td>\n",
       "      <td>内蒙古</td>\n",
       "      <td>-0.14</td>\n",
       "      <td>2.452372e+07</td>\n",
       "      <td>-4.745650e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>34915616</td>\n",
       "      <td>2.47</td>\n",
       "      <td>2.67</td>\n",
       "      <td>山西</td>\n",
       "      <td>-0.20</td>\n",
       "      <td>3.558605e+07</td>\n",
       "      <td>-6.704342e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>42591407</td>\n",
       "      <td>3.02</td>\n",
       "      <td>3.27</td>\n",
       "      <td>辽宁</td>\n",
       "      <td>-0.25</td>\n",
       "      <td>4.358292e+07</td>\n",
       "      <td>-9.915084e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>24073453</td>\n",
       "      <td>1.71</td>\n",
       "      <td>2.05</td>\n",
       "      <td>吉林</td>\n",
       "      <td>-0.34</td>\n",
       "      <td>2.732262e+07</td>\n",
       "      <td>-3.249170e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>31850088</td>\n",
       "      <td>2.26</td>\n",
       "      <td>2.86</td>\n",
       "      <td>黑龙江</td>\n",
       "      <td>-0.60</td>\n",
       "      <td>3.811839e+07</td>\n",
       "      <td>-6.268303e+06</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Unnamed: 0     人口数(人)  2020年比重(%)  2010年比重(%)   地区  增长比例       2010年人数  \\\n",
       "19          19  126012510        8.93        7.79   广东  1.14  1.038260e+08   \n",
       "11          11   64567588        4.57        4.06   浙江  0.51  5.411212e+07   \n",
       "10          10   84748016        6.00        5.87   江苏  0.13  7.823600e+07   \n",
       "15          15  101527453        7.19        7.15   山东  0.04  9.529598e+07   \n",
       "16          16   99365519        7.04        7.02   河南  0.02  9.356332e+07   \n",
       "13          13   41540086        2.94        2.75   福建  0.19  3.665230e+07   \n",
       "20          20   50126804        3.55        3.44   广西  0.11  4.584869e+07   \n",
       "31          31   25852345        1.83        1.63   新疆  0.20  2.172482e+07   \n",
       "24          24   38562148        2.73        2.59   贵州  0.14  3.451980e+07   \n",
       "23          23   83674866        5.93        6.00   四川 -0.07  7.996865e+07   \n",
       "22          22   32054159        2.27        2.15   重庆  0.12  2.865543e+07   \n",
       "3            3   74610235        5.28        5.36   河北 -0.08  7.143866e+07   \n",
       "1            1   21893095        1.55        1.46   北京  0.09  1.945904e+07   \n",
       "27          27   39528999        2.80        2.79   陕西  0.01  3.718542e+07   \n",
       "9            9   24870895        1.76        1.72   上海  0.04  2.292435e+07   \n",
       "12          12   61027171        4.32        4.44   安徽 -0.12  5.917680e+07   \n",
       "25          25   47209277        3.34        3.43   云南 -0.09  4.571541e+07   \n",
       "21          21   10081232        0.71        0.65   海南  0.06  8.663271e+06   \n",
       "18          18   66444864        4.71        4.90   湖南 -0.19  6.530773e+07   \n",
       "30          30    7202654        0.51        0.47   宁夏  0.04  6.264211e+06   \n",
       "2            2   13866009        0.98        0.97   天津  0.01  1.292827e+07   \n",
       "17          17   57752557        4.09        4.27   湖北 -0.18  5.691102e+07   \n",
       "14          14   45188635        3.20        3.33   江西 -0.13  4.438260e+07   \n",
       "26          26    3648100        0.26        0.22   西藏  0.04  2.932184e+06   \n",
       "29          29    5923957        0.42        0.42   青海  0.00  5.597806e+06   \n",
       "28          28   25019831        1.77        1.91   甘肃 -0.14  2.545669e+07   \n",
       "5            5   24049155        1.70        1.84  内蒙古 -0.14  2.452372e+07   \n",
       "4            4   34915616        2.47        2.67   山西 -0.20  3.558605e+07   \n",
       "6            6   42591407        3.02        3.27   辽宁 -0.25  4.358292e+07   \n",
       "7            7   24073453        1.71        2.05   吉林 -0.34  2.732262e+07   \n",
       "8            8   31850088        2.26        2.86  黑龙江 -0.60  3.811839e+07   \n",
       "\n",
       "         10年增长人数  \n",
       "19  2.218654e+07  \n",
       "11  1.045547e+07  \n",
       "10  6.512018e+06  \n",
       "15  6.231476e+06  \n",
       "16  5.802196e+06  \n",
       "13  4.887787e+06  \n",
       "20  4.278110e+06  \n",
       "31  4.127528e+06  \n",
       "24  4.042346e+06  \n",
       "23  3.706214e+06  \n",
       "22  3.398725e+06  \n",
       "3   3.171572e+06  \n",
       "1   2.434056e+06  \n",
       "27  2.343576e+06  \n",
       "9   1.946548e+06  \n",
       "12  1.850368e+06  \n",
       "25  1.493864e+06  \n",
       "21  1.417961e+06  \n",
       "18  1.137131e+06  \n",
       "30  9.384429e+05  \n",
       "2   9.377436e+05  \n",
       "17  8.415329e+05  \n",
       "14  8.060331e+05  \n",
       "26  7.159161e+05  \n",
       "29  3.261514e+05  \n",
       "28 -4.368566e+05  \n",
       "5  -4.745650e+05  \n",
       "4  -6.704342e+05  \n",
       "6  -9.915084e+05  \n",
       "7  -3.249170e+06  \n",
       "8  -6.268303e+06  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据计算，得出新的表格\n",
    "population1 = pd.read_csv('data/各地区人口构成数据.csv')\n",
    "population1['增长比例'] = population1['2020年比重(%)'] - population1['2010年比重(%)']\n",
    "population1['2010年人数'] = 13328108.69 * population1['2010年比重(%)']\n",
    "population1['10年增长人数'] = population1['人口数(人)'] - population1['2010年人数']\n",
    "\n",
    "# 排序\n",
    "population1.sort_values(by='10年增长人数',inplace=True,ascending=False)\n",
    "population1.drop(index=[0],inplace=True)\n",
    "population1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导出数据\n",
    "population1.to_csv('data/2010与2020各地区人口构成数据.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "population1 = pd.read_csv('data/2010与2020各地区人口构成数据.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "line=(\n",
    "    Line()\n",
    "    .add_xaxis(xaxis_data=population1['地区'].tolist())\n",
    "    .add_yaxis(series_name=\"人数线\",y_axis=population1['10年增长人数'].tolist(), is_smooth=True)\n",
    "#     .add_yaxis(series_name=\"y2线\",y_axis=population1.head()['人口数(人)'], is_smooth=True)\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"中国十年增长人数折线图\",\n",
    "                                               subtitle=\"数据表明，2010至2020年广东人口增长了2千多万，黑龙江人口负增长500多万。\\n进一步说明了人口向经济发达区域、城市群进一步集聚。\",\n",
    "                                               title_textstyle_opts=opts.TextStyleOpts(font_size=25,), \n",
    "                                               pos_left=\"center\", pos_top=\"0\",),\n",
    "                     \n",
    "                     legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"35%\", pos_left=\"90%\"))\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))\n",
    "    .render('html/中国十年增长人数折线图.html')\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 各地区人口性别构成_地图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>男性比重(%)</th>\n",
       "      <th>女性比重(%)</th>\n",
       "      <th>性别比(%)</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>51.24</td>\n",
       "      <td>48.76</td>\n",
       "      <td>105.07</td>\n",
       "      <td>全国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>51.14</td>\n",
       "      <td>48.86</td>\n",
       "      <td>104.65</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>51.53</td>\n",
       "      <td>48.47</td>\n",
       "      <td>106.31</td>\n",
       "      <td>天津</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>50.50</td>\n",
       "      <td>49.50</td>\n",
       "      <td>102.02</td>\n",
       "      <td>河北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>50.99</td>\n",
       "      <td>49.01</td>\n",
       "      <td>104.06</td>\n",
       "      <td>山西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>51.04</td>\n",
       "      <td>48.96</td>\n",
       "      <td>104.26</td>\n",
       "      <td>内蒙古</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>49.92</td>\n",
       "      <td>50.08</td>\n",
       "      <td>99.70</td>\n",
       "      <td>辽宁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>49.92</td>\n",
       "      <td>50.08</td>\n",
       "      <td>99.69</td>\n",
       "      <td>吉林</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>50.09</td>\n",
       "      <td>49.91</td>\n",
       "      <td>100.35</td>\n",
       "      <td>黑龙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>51.77</td>\n",
       "      <td>48.23</td>\n",
       "      <td>107.33</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>50.78</td>\n",
       "      <td>49.22</td>\n",
       "      <td>103.15</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>11</td>\n",
       "      <td>52.16</td>\n",
       "      <td>47.84</td>\n",
       "      <td>109.04</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>12</td>\n",
       "      <td>50.97</td>\n",
       "      <td>49.03</td>\n",
       "      <td>103.94</td>\n",
       "      <td>安徽</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>13</td>\n",
       "      <td>51.68</td>\n",
       "      <td>48.32</td>\n",
       "      <td>106.94</td>\n",
       "      <td>福建</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>14</td>\n",
       "      <td>51.60</td>\n",
       "      <td>48.40</td>\n",
       "      <td>106.62</td>\n",
       "      <td>江西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>15</td>\n",
       "      <td>50.66</td>\n",
       "      <td>49.34</td>\n",
       "      <td>102.67</td>\n",
       "      <td>山东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>16</td>\n",
       "      <td>50.15</td>\n",
       "      <td>49.85</td>\n",
       "      <td>100.60</td>\n",
       "      <td>河南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>17</td>\n",
       "      <td>51.42</td>\n",
       "      <td>48.58</td>\n",
       "      <td>105.83</td>\n",
       "      <td>湖北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>18</td>\n",
       "      <td>51.16</td>\n",
       "      <td>48.84</td>\n",
       "      <td>104.77</td>\n",
       "      <td>湖南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>19</td>\n",
       "      <td>53.07</td>\n",
       "      <td>46.93</td>\n",
       "      <td>113.08</td>\n",
       "      <td>广东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>20</td>\n",
       "      <td>51.70</td>\n",
       "      <td>48.30</td>\n",
       "      <td>107.04</td>\n",
       "      <td>广西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>21</td>\n",
       "      <td>53.02</td>\n",
       "      <td>46.98</td>\n",
       "      <td>112.86</td>\n",
       "      <td>海南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>22</td>\n",
       "      <td>50.55</td>\n",
       "      <td>49.45</td>\n",
       "      <td>102.21</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>23</td>\n",
       "      <td>50.54</td>\n",
       "      <td>49.46</td>\n",
       "      <td>102.19</td>\n",
       "      <td>四川</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>24</td>\n",
       "      <td>51.10</td>\n",
       "      <td>48.90</td>\n",
       "      <td>104.50</td>\n",
       "      <td>贵州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>25</td>\n",
       "      <td>51.73</td>\n",
       "      <td>48.27</td>\n",
       "      <td>107.16</td>\n",
       "      <td>云南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>26</td>\n",
       "      <td>52.45</td>\n",
       "      <td>47.55</td>\n",
       "      <td>110.32</td>\n",
       "      <td>西藏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>27</td>\n",
       "      <td>51.17</td>\n",
       "      <td>48.83</td>\n",
       "      <td>104.79</td>\n",
       "      <td>陕西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>28</td>\n",
       "      <td>50.76</td>\n",
       "      <td>49.24</td>\n",
       "      <td>103.10</td>\n",
       "      <td>甘肃</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>29</td>\n",
       "      <td>51.21</td>\n",
       "      <td>48.79</td>\n",
       "      <td>104.97</td>\n",
       "      <td>青海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>30</td>\n",
       "      <td>50.94</td>\n",
       "      <td>49.06</td>\n",
       "      <td>103.83</td>\n",
       "      <td>宁夏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>31</td>\n",
       "      <td>51.66</td>\n",
       "      <td>48.34</td>\n",
       "      <td>106.85</td>\n",
       "      <td>新疆</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Unnamed: 0  男性比重(%)  女性比重(%)  性别比(%)   地区\n",
       "0            0    51.24    48.76  105.07   全国\n",
       "1            1    51.14    48.86  104.65   北京\n",
       "2            2    51.53    48.47  106.31   天津\n",
       "3            3    50.50    49.50  102.02   河北\n",
       "4            4    50.99    49.01  104.06   山西\n",
       "5            5    51.04    48.96  104.26  内蒙古\n",
       "6            6    49.92    50.08   99.70   辽宁\n",
       "7            7    49.92    50.08   99.69   吉林\n",
       "8            8    50.09    49.91  100.35  黑龙江\n",
       "9            9    51.77    48.23  107.33   上海\n",
       "10          10    50.78    49.22  103.15   江苏\n",
       "11          11    52.16    47.84  109.04   浙江\n",
       "12          12    50.97    49.03  103.94   安徽\n",
       "13          13    51.68    48.32  106.94   福建\n",
       "14          14    51.60    48.40  106.62   江西\n",
       "15          15    50.66    49.34  102.67   山东\n",
       "16          16    50.15    49.85  100.60   河南\n",
       "17          17    51.42    48.58  105.83   湖北\n",
       "18          18    51.16    48.84  104.77   湖南\n",
       "19          19    53.07    46.93  113.08   广东\n",
       "20          20    51.70    48.30  107.04   广西\n",
       "21          21    53.02    46.98  112.86   海南\n",
       "22          22    50.55    49.45  102.21   重庆\n",
       "23          23    50.54    49.46  102.19   四川\n",
       "24          24    51.10    48.90  104.50   贵州\n",
       "25          25    51.73    48.27  107.16   云南\n",
       "26          26    52.45    47.55  110.32   西藏\n",
       "27          27    51.17    48.83  104.79   陕西\n",
       "28          28    50.76    49.24  103.10   甘肃\n",
       "29          29    51.21    48.79  104.97   青海\n",
       "30          30    50.94    49.06  103.83   宁夏\n",
       "31          31    51.66    48.34  106.85   新疆"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gender = pd.read_csv('data/各地区人口性别构成数据.csv')\n",
    "gender"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 排序\n",
    "gender.sort_values(by='性别比(%)',inplace=True,ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\1\\\\Desktop\\\\第七次人口普查数据\\\\html\\\\全国人口性别比地图.html'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_data = gender['地区'].tolist()\n",
    "y_data = gender['性别比(%)'].tolist()\n",
    "\n",
    "m = Map()\n",
    "m.add('',[list(z) for z in zip(x_data,y_data)],maptype = 'china',is_map_symbol_show=False)\n",
    "m.set_series_opts(label_opts = opts.LabelOpts(is_show=True))\n",
    "m.set_global_opts(title_opts = opts.TitleOpts(title = '全国人口性别比地图', \n",
    "                                              subtitle = \"注:性别比是在种群层面上研究的问题，是指族群中雄性（男性）对雌性（女性）的比率。\\n\\n数据表明，广东省的男女比例失衡最严重。东北三省的男女比例最为均衡，还出现了性别比99%的情况。\\n其实，这也可以看出，劳动力流失问题。\\n中国，已经成为世界上出生性别比失衡较为严重、持续时间较长的国家。\"),\n",
    "                  \n",
    "visualmap_opts = opts.VisualMapOpts(min_=gender['性别比(%)'].min(),max_=gender['性别比(%)'].max(),\n",
    "range_color=['#FF99CC','#CC99CC','#CC3399']))\n",
    "m.render('html/全国人口性别比地图.html')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 全国人口年龄占比_饼状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>年龄</th>\n",
       "      <th>人口数(人)</th>\n",
       "      <th>比重(%)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>总　计</td>\n",
       "      <td>1411778724</td>\n",
       "      <td>100.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0—14岁</td>\n",
       "      <td>253383938</td>\n",
       "      <td>17.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>15—59岁</td>\n",
       "      <td>894376020</td>\n",
       "      <td>63.35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>60岁及以上</td>\n",
       "      <td>264018766</td>\n",
       "      <td>18.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>其中：65岁及以上</td>\n",
       "      <td>190635280</td>\n",
       "      <td>13.50</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Unnamed: 0         年龄      人口数(人)   比重(%)\n",
       "0           0        总　计  1411778724  100.00\n",
       "1           1      0—14岁   253383938   17.95\n",
       "2           2     15—59岁   894376020   63.35\n",
       "3           3     60岁及以上   264018766   18.70\n",
       "4           4  其中：65岁及以上   190635280   13.50"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_country = pd.read_csv('data/全国人口年龄构成数据.csv')\n",
    "age_country"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删掉总计的数据\n",
    "age_country.drop(index=[0],inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_data = age_country['年龄'].tolist()\n",
    "y_data = age_country['比重(%)'].tolist()\n",
    "c = (\n",
    "    Pie()\n",
    "    .add(\"\", [list(z) for z in zip(x_data,y_data)],\n",
    "         # 调整饼图位置\n",
    "         center=[\"50%\", \"60%\"])\n",
    "    .set_series_opts(label_opts = opts.LabelOpts(is_show=True))\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"全国人口年龄占比饼状图\",\n",
    "                                              subtitle =\"国际上通常把60岁以上的人口占总人口比例达到10%，或65岁以上人口占总人口的比重达到7%作为国家或地区进入老龄化社会的标准。\\ n65岁及以上人口的比例超过10％表明老龄化已经非常严重了。\\n\\n然而，中国人口总数中的65岁及以上人口已经占了13.50%，老龄化非常严重。因此，国家发布三胎政策以缓解老龄化问题。\",\n",
    "                                              pos_top=\"0\",),\n",
    "                     # 标签放到左边\n",
    "                     legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"35%\", pos_left=\"2%\"),)\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}: {c}\"))\n",
    "    .render(\"html/全国人口年龄占比饼状图.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 各地区每10万人口中拥有的各类受教育程度人数_地图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>大学（大专及以上）</th>\n",
       "      <th>高中（含中专）</th>\n",
       "      <th>初中</th>\n",
       "      <th>小学</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>15467</td>\n",
       "      <td>15088</td>\n",
       "      <td>34507</td>\n",
       "      <td>24767</td>\n",
       "      <td>全国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>41980</td>\n",
       "      <td>17593</td>\n",
       "      <td>23289</td>\n",
       "      <td>10503</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>26940</td>\n",
       "      <td>17719</td>\n",
       "      <td>32294</td>\n",
       "      <td>16123</td>\n",
       "      <td>天津</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>12418</td>\n",
       "      <td>13861</td>\n",
       "      <td>39950</td>\n",
       "      <td>24664</td>\n",
       "      <td>河北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>17358</td>\n",
       "      <td>16485</td>\n",
       "      <td>38950</td>\n",
       "      <td>19506</td>\n",
       "      <td>山西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>18688</td>\n",
       "      <td>14814</td>\n",
       "      <td>33861</td>\n",
       "      <td>23627</td>\n",
       "      <td>内蒙古</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>18216</td>\n",
       "      <td>14670</td>\n",
       "      <td>42799</td>\n",
       "      <td>18888</td>\n",
       "      <td>辽宁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>16738</td>\n",
       "      <td>17080</td>\n",
       "      <td>38234</td>\n",
       "      <td>22318</td>\n",
       "      <td>吉林</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>14793</td>\n",
       "      <td>15525</td>\n",
       "      <td>42793</td>\n",
       "      <td>21863</td>\n",
       "      <td>黑龙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>33872</td>\n",
       "      <td>19020</td>\n",
       "      <td>28935</td>\n",
       "      <td>11929</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>18663</td>\n",
       "      <td>16191</td>\n",
       "      <td>33308</td>\n",
       "      <td>22742</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>11</td>\n",
       "      <td>16990</td>\n",
       "      <td>14555</td>\n",
       "      <td>32706</td>\n",
       "      <td>26384</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>12</td>\n",
       "      <td>13280</td>\n",
       "      <td>13294</td>\n",
       "      <td>33724</td>\n",
       "      <td>26875</td>\n",
       "      <td>安徽</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>13</td>\n",
       "      <td>14148</td>\n",
       "      <td>14212</td>\n",
       "      <td>32218</td>\n",
       "      <td>28031</td>\n",
       "      <td>福建</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>14</td>\n",
       "      <td>11897</td>\n",
       "      <td>15145</td>\n",
       "      <td>35501</td>\n",
       "      <td>27514</td>\n",
       "      <td>江西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>15</td>\n",
       "      <td>14384</td>\n",
       "      <td>14334</td>\n",
       "      <td>35778</td>\n",
       "      <td>23693</td>\n",
       "      <td>山东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>16</td>\n",
       "      <td>11744</td>\n",
       "      <td>15239</td>\n",
       "      <td>37518</td>\n",
       "      <td>24557</td>\n",
       "      <td>河南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>17</td>\n",
       "      <td>15502</td>\n",
       "      <td>17428</td>\n",
       "      <td>34280</td>\n",
       "      <td>23520</td>\n",
       "      <td>湖北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>18</td>\n",
       "      <td>12239</td>\n",
       "      <td>17776</td>\n",
       "      <td>35636</td>\n",
       "      <td>25214</td>\n",
       "      <td>湖南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>19</td>\n",
       "      <td>15699</td>\n",
       "      <td>18224</td>\n",
       "      <td>35484</td>\n",
       "      <td>20676</td>\n",
       "      <td>广东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>20</td>\n",
       "      <td>10806</td>\n",
       "      <td>12962</td>\n",
       "      <td>36388</td>\n",
       "      <td>27855</td>\n",
       "      <td>广西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>21</td>\n",
       "      <td>13919</td>\n",
       "      <td>15561</td>\n",
       "      <td>40174</td>\n",
       "      <td>19701</td>\n",
       "      <td>海南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>22</td>\n",
       "      <td>15412</td>\n",
       "      <td>15956</td>\n",
       "      <td>30582</td>\n",
       "      <td>29894</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>23</td>\n",
       "      <td>13267</td>\n",
       "      <td>13301</td>\n",
       "      <td>31443</td>\n",
       "      <td>31317</td>\n",
       "      <td>四川</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>24</td>\n",
       "      <td>10952</td>\n",
       "      <td>9951</td>\n",
       "      <td>30464</td>\n",
       "      <td>31921</td>\n",
       "      <td>贵州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>25</td>\n",
       "      <td>11601</td>\n",
       "      <td>10338</td>\n",
       "      <td>29241</td>\n",
       "      <td>35667</td>\n",
       "      <td>云南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>26</td>\n",
       "      <td>11019</td>\n",
       "      <td>7051</td>\n",
       "      <td>15757</td>\n",
       "      <td>32108</td>\n",
       "      <td>西藏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>27</td>\n",
       "      <td>18397</td>\n",
       "      <td>15581</td>\n",
       "      <td>33979</td>\n",
       "      <td>21686</td>\n",
       "      <td>陕西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>28</td>\n",
       "      <td>14506</td>\n",
       "      <td>12937</td>\n",
       "      <td>27423</td>\n",
       "      <td>29808</td>\n",
       "      <td>甘肃</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>29</td>\n",
       "      <td>14880</td>\n",
       "      <td>10568</td>\n",
       "      <td>24344</td>\n",
       "      <td>32725</td>\n",
       "      <td>青海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>30</td>\n",
       "      <td>17340</td>\n",
       "      <td>13432</td>\n",
       "      <td>29717</td>\n",
       "      <td>26111</td>\n",
       "      <td>宁夏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>31</td>\n",
       "      <td>16536</td>\n",
       "      <td>13208</td>\n",
       "      <td>31559</td>\n",
       "      <td>28405</td>\n",
       "      <td>新疆</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Unnamed: 0  大学（大专及以上）  高中（含中专）     初中     小学   地区\n",
       "0            0      15467    15088  34507  24767   全国\n",
       "1            1      41980    17593  23289  10503   北京\n",
       "2            2      26940    17719  32294  16123   天津\n",
       "3            3      12418    13861  39950  24664   河北\n",
       "4            4      17358    16485  38950  19506   山西\n",
       "5            5      18688    14814  33861  23627  内蒙古\n",
       "6            6      18216    14670  42799  18888   辽宁\n",
       "7            7      16738    17080  38234  22318   吉林\n",
       "8            8      14793    15525  42793  21863  黑龙江\n",
       "9            9      33872    19020  28935  11929   上海\n",
       "10          10      18663    16191  33308  22742   江苏\n",
       "11          11      16990    14555  32706  26384   浙江\n",
       "12          12      13280    13294  33724  26875   安徽\n",
       "13          13      14148    14212  32218  28031   福建\n",
       "14          14      11897    15145  35501  27514   江西\n",
       "15          15      14384    14334  35778  23693   山东\n",
       "16          16      11744    15239  37518  24557   河南\n",
       "17          17      15502    17428  34280  23520   湖北\n",
       "18          18      12239    17776  35636  25214   湖南\n",
       "19          19      15699    18224  35484  20676   广东\n",
       "20          20      10806    12962  36388  27855   广西\n",
       "21          21      13919    15561  40174  19701   海南\n",
       "22          22      15412    15956  30582  29894   重庆\n",
       "23          23      13267    13301  31443  31317   四川\n",
       "24          24      10952     9951  30464  31921   贵州\n",
       "25          25      11601    10338  29241  35667   云南\n",
       "26          26      11019     7051  15757  32108   西藏\n",
       "27          27      18397    15581  33979  21686   陕西\n",
       "28          28      14506    12937  27423  29808   甘肃\n",
       "29          29      14880    10568  24344  32725   青海\n",
       "30          30      17340    13432  29717  26111   宁夏\n",
       "31          31      16536    13208  31559  28405   新疆"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "education = pd.read_csv('data/各地区每10万人口中拥有的各类受教育程度人数数据.csv')\n",
    "education"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# education.sort_values('大学（大专及以上）',inplace = True,ascending = False)\n",
    "# education.plot.bar(x = '地区',y = ['小学','初中','高中（含中专）','大学（大专及以上）'],stacked = True)\n",
    "# plt.title('各地区每 10 万人口不同教育程度的人数',loc = 'left',fontsize = 20)\n",
    "# plt.legend(bbox_to_anchor =(1,1.1),ncol = 10,facecolor = 'None')\n",
    "# plt.xlabel('')\n",
    "# plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删掉全国的数据\n",
    "education.drop(index=[0],inplace=True)\n",
    "# education"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\1\\\\Desktop\\\\第七次人口普查数据\\\\html\\\\各地每10万人中大学以上学历的人口分布.html'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 绘制全国各地每10人中大学以上的人数，以地图展示\n",
    "x_data = education['地区'].tolist()\n",
    "y_data = education['大学（大专及以上）'].tolist()\n",
    "\n",
    "m = Map()\n",
    "m.add('',[list(z) for z in zip(x_data,y_data)],maptype = 'china',is_map_symbol_show=False)\n",
    "m.set_series_opts(label_opts = opts.LabelOpts(is_show=True))\n",
    "m.set_global_opts(title_opts = opts.TitleOpts(title = '全国各地每10万人中大学以上学历的人口分布',\n",
    "                                              subtitle='北京是全国的文化中心，人才的聚集地。\\n\\n上海是全国的经济中心，发展历史悠久，对于人才也非常有吸引力。名牌大学、重点大学，也有集中扎堆的现象，主要分布在北京、上海。', ),\n",
    "visualmap_opts = opts.VisualMapOpts(min_=education['大学（大专及以上）'].min(),max_=education['大学（大专及以上）'].max(),range_color=['#FFFF99','#99CC99','#666600']))\n",
    "m.render('html/各地每10万人中大学以上学历的人口分布.html')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 北上广三地大学学历人数比较图_柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>大学（大专及以上）</th>\n",
       "      <th>高中（含中专）</th>\n",
       "      <th>初中</th>\n",
       "      <th>小学</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>26940</td>\n",
       "      <td>17719</td>\n",
       "      <td>32294</td>\n",
       "      <td>16123</td>\n",
       "      <td>天津</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>18663</td>\n",
       "      <td>16191</td>\n",
       "      <td>33308</td>\n",
       "      <td>22742</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>20</td>\n",
       "      <td>10806</td>\n",
       "      <td>12962</td>\n",
       "      <td>36388</td>\n",
       "      <td>27855</td>\n",
       "      <td>广西</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Unnamed: 0  大学（大专及以上）  高中（含中专）     初中     小学  地区\n",
       "2            2      26940    17719  32294  16123  天津\n",
       "10          10      18663    16191  33308  22742  江苏\n",
       "20          20      10806    12962  36388  27855  广西"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 抽取出北京、上海、广东个地区进行分析\n",
    "education_3 = education.iloc[[1,9,19]]\n",
    "education_3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 指定柱子颜色的js代码\n",
    "color_function = \"\"\"\n",
    "        function (params) {\n",
    "            if (params.value < 20000) \n",
    "                return '#66CC99';\n",
    "            else if (params.value > 30000 && params.value < 35000) \n",
    "                return '#66CCCC';\n",
    "            else return '#009999';\n",
    "        }\n",
    "        \"\"\"\n",
    "\n",
    "b = (\n",
    "    Bar()\n",
    "    .add_xaxis(education_3['地区'].tolist())      # x轴\n",
    "    .add_yaxis(series_name=\"三地比较\", y_axis=education_3['大学（大专及以上）'].tolist(),itemstyle_opts=opts.ItemStyleOpts(color=JsCode(color_function)))\n",
    "\n",
    "#     .reversal_axis()   # xy轴交换\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='北上广三地大学学历人数比较图',\n",
    "                                  subtitle='北京、上海、广州、深圳是中国的超一线城市，对于人才引进都应非常重视。\\n\\n然而，广东省主要是在改革开放后经济才迅速发展，与北京、上海相比，人才资源明显不足。\\n\\n广东省仍需加强人才政策实施。', \n",
    "                                  title_textstyle_opts=opts.TextStyleOpts(), pos_left=\"center\", pos_top=\"0\",),\n",
    "        legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"35%\", pos_right=\"0%\"),\n",
    "    )\n",
    "    .render(\"html/北上广三地大学学历人数比较图.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 老龄化程度对比图_柱状图、折线图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>0-14岁比重(%)</th>\n",
       "      <th>15-59岁比重(%)</th>\n",
       "      <th>60岁及以上比重(%)</th>\n",
       "      <th>其中65岁及以上比重(%)</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>17.95</td>\n",
       "      <td>63.35</td>\n",
       "      <td>18.70</td>\n",
       "      <td>13.50</td>\n",
       "      <td>全国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>11.84</td>\n",
       "      <td>68.53</td>\n",
       "      <td>19.63</td>\n",
       "      <td>13.30</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>13.47</td>\n",
       "      <td>64.87</td>\n",
       "      <td>21.66</td>\n",
       "      <td>14.75</td>\n",
       "      <td>天津</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>20.22</td>\n",
       "      <td>59.92</td>\n",
       "      <td>19.85</td>\n",
       "      <td>13.92</td>\n",
       "      <td>河北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>16.35</td>\n",
       "      <td>64.72</td>\n",
       "      <td>18.92</td>\n",
       "      <td>12.90</td>\n",
       "      <td>山西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>14.04</td>\n",
       "      <td>66.17</td>\n",
       "      <td>19.78</td>\n",
       "      <td>13.05</td>\n",
       "      <td>内蒙古</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>11.12</td>\n",
       "      <td>63.16</td>\n",
       "      <td>25.72</td>\n",
       "      <td>17.42</td>\n",
       "      <td>辽宁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>11.71</td>\n",
       "      <td>65.23</td>\n",
       "      <td>23.06</td>\n",
       "      <td>15.61</td>\n",
       "      <td>吉林</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>10.32</td>\n",
       "      <td>66.46</td>\n",
       "      <td>23.22</td>\n",
       "      <td>15.61</td>\n",
       "      <td>黑龙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>9.80</td>\n",
       "      <td>66.82</td>\n",
       "      <td>23.38</td>\n",
       "      <td>16.28</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>15.21</td>\n",
       "      <td>62.95</td>\n",
       "      <td>21.84</td>\n",
       "      <td>16.20</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>11</td>\n",
       "      <td>13.45</td>\n",
       "      <td>67.86</td>\n",
       "      <td>18.70</td>\n",
       "      <td>13.27</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>12</td>\n",
       "      <td>19.24</td>\n",
       "      <td>61.96</td>\n",
       "      <td>18.79</td>\n",
       "      <td>15.01</td>\n",
       "      <td>安徽</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>13</td>\n",
       "      <td>19.32</td>\n",
       "      <td>64.70</td>\n",
       "      <td>15.98</td>\n",
       "      <td>11.10</td>\n",
       "      <td>福建</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>14</td>\n",
       "      <td>21.96</td>\n",
       "      <td>61.17</td>\n",
       "      <td>16.87</td>\n",
       "      <td>11.89</td>\n",
       "      <td>江西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>15</td>\n",
       "      <td>18.78</td>\n",
       "      <td>60.32</td>\n",
       "      <td>20.90</td>\n",
       "      <td>15.13</td>\n",
       "      <td>山东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>16</td>\n",
       "      <td>23.14</td>\n",
       "      <td>58.79</td>\n",
       "      <td>18.08</td>\n",
       "      <td>13.49</td>\n",
       "      <td>河南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>17</td>\n",
       "      <td>16.31</td>\n",
       "      <td>63.26</td>\n",
       "      <td>20.42</td>\n",
       "      <td>14.59</td>\n",
       "      <td>湖北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>18</td>\n",
       "      <td>19.52</td>\n",
       "      <td>60.60</td>\n",
       "      <td>19.88</td>\n",
       "      <td>14.81</td>\n",
       "      <td>湖南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>19</td>\n",
       "      <td>18.85</td>\n",
       "      <td>68.80</td>\n",
       "      <td>12.35</td>\n",
       "      <td>8.58</td>\n",
       "      <td>广东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>20</td>\n",
       "      <td>23.63</td>\n",
       "      <td>59.69</td>\n",
       "      <td>16.69</td>\n",
       "      <td>12.20</td>\n",
       "      <td>广西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>21</td>\n",
       "      <td>19.97</td>\n",
       "      <td>65.38</td>\n",
       "      <td>14.65</td>\n",
       "      <td>10.43</td>\n",
       "      <td>海南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>22</td>\n",
       "      <td>15.91</td>\n",
       "      <td>62.22</td>\n",
       "      <td>21.87</td>\n",
       "      <td>17.08</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>23</td>\n",
       "      <td>16.10</td>\n",
       "      <td>62.19</td>\n",
       "      <td>21.71</td>\n",
       "      <td>16.93</td>\n",
       "      <td>四川</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>24</td>\n",
       "      <td>23.97</td>\n",
       "      <td>60.65</td>\n",
       "      <td>15.38</td>\n",
       "      <td>11.56</td>\n",
       "      <td>贵州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>25</td>\n",
       "      <td>19.57</td>\n",
       "      <td>65.52</td>\n",
       "      <td>14.91</td>\n",
       "      <td>10.75</td>\n",
       "      <td>云南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>26</td>\n",
       "      <td>24.53</td>\n",
       "      <td>66.95</td>\n",
       "      <td>8.52</td>\n",
       "      <td>5.67</td>\n",
       "      <td>西藏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>27</td>\n",
       "      <td>17.33</td>\n",
       "      <td>63.46</td>\n",
       "      <td>19.20</td>\n",
       "      <td>13.32</td>\n",
       "      <td>陕西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>28</td>\n",
       "      <td>19.40</td>\n",
       "      <td>63.57</td>\n",
       "      <td>17.03</td>\n",
       "      <td>12.58</td>\n",
       "      <td>甘肃</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>29</td>\n",
       "      <td>20.81</td>\n",
       "      <td>67.04</td>\n",
       "      <td>12.14</td>\n",
       "      <td>8.68</td>\n",
       "      <td>青海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>30</td>\n",
       "      <td>20.38</td>\n",
       "      <td>66.09</td>\n",
       "      <td>13.52</td>\n",
       "      <td>9.62</td>\n",
       "      <td>宁夏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>31</td>\n",
       "      <td>22.46</td>\n",
       "      <td>66.26</td>\n",
       "      <td>11.28</td>\n",
       "      <td>7.76</td>\n",
       "      <td>新疆</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Unnamed: 0  0-14岁比重(%)  15-59岁比重(%)  60岁及以上比重(%)  其中65岁及以上比重(%)   地区\n",
       "0            0       17.95        63.35        18.70          13.50   全国\n",
       "1            1       11.84        68.53        19.63          13.30   北京\n",
       "2            2       13.47        64.87        21.66          14.75   天津\n",
       "3            3       20.22        59.92        19.85          13.92   河北\n",
       "4            4       16.35        64.72        18.92          12.90   山西\n",
       "5            5       14.04        66.17        19.78          13.05  内蒙古\n",
       "6            6       11.12        63.16        25.72          17.42   辽宁\n",
       "7            7       11.71        65.23        23.06          15.61   吉林\n",
       "8            8       10.32        66.46        23.22          15.61  黑龙江\n",
       "9            9        9.80        66.82        23.38          16.28   上海\n",
       "10          10       15.21        62.95        21.84          16.20   江苏\n",
       "11          11       13.45        67.86        18.70          13.27   浙江\n",
       "12          12       19.24        61.96        18.79          15.01   安徽\n",
       "13          13       19.32        64.70        15.98          11.10   福建\n",
       "14          14       21.96        61.17        16.87          11.89   江西\n",
       "15          15       18.78        60.32        20.90          15.13   山东\n",
       "16          16       23.14        58.79        18.08          13.49   河南\n",
       "17          17       16.31        63.26        20.42          14.59   湖北\n",
       "18          18       19.52        60.60        19.88          14.81   湖南\n",
       "19          19       18.85        68.80        12.35           8.58   广东\n",
       "20          20       23.63        59.69        16.69          12.20   广西\n",
       "21          21       19.97        65.38        14.65          10.43   海南\n",
       "22          22       15.91        62.22        21.87          17.08   重庆\n",
       "23          23       16.10        62.19        21.71          16.93   四川\n",
       "24          24       23.97        60.65        15.38          11.56   贵州\n",
       "25          25       19.57        65.52        14.91          10.75   云南\n",
       "26          26       24.53        66.95         8.52           5.67   西藏\n",
       "27          27       17.33        63.46        19.20          13.32   陕西\n",
       "28          28       19.40        63.57        17.03          12.58   甘肃\n",
       "29          29       20.81        67.04        12.14           8.68   青海\n",
       "30          30       20.38        66.09        13.52           9.62   宁夏\n",
       "31          31       22.46        66.26        11.28           7.76   新疆"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_region = pd.read_csv('data/各地区人口年龄构成数据.csv')\n",
    "age_region"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>0-14岁比重(%)</th>\n",
       "      <th>15-59岁比重(%)</th>\n",
       "      <th>60岁及以上比重(%)</th>\n",
       "      <th>其中65岁及以上比重(%)</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6</td>\n",
       "      <td>11.12</td>\n",
       "      <td>63.16</td>\n",
       "      <td>25.72</td>\n",
       "      <td>17.42</td>\n",
       "      <td>辽宁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>22</td>\n",
       "      <td>15.91</td>\n",
       "      <td>62.22</td>\n",
       "      <td>21.87</td>\n",
       "      <td>17.08</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>23</td>\n",
       "      <td>16.10</td>\n",
       "      <td>62.19</td>\n",
       "      <td>21.71</td>\n",
       "      <td>16.93</td>\n",
       "      <td>四川</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9</td>\n",
       "      <td>9.80</td>\n",
       "      <td>66.82</td>\n",
       "      <td>23.38</td>\n",
       "      <td>16.28</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10</td>\n",
       "      <td>15.21</td>\n",
       "      <td>62.95</td>\n",
       "      <td>21.84</td>\n",
       "      <td>16.20</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7</td>\n",
       "      <td>11.71</td>\n",
       "      <td>65.23</td>\n",
       "      <td>23.06</td>\n",
       "      <td>15.61</td>\n",
       "      <td>吉林</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>8</td>\n",
       "      <td>10.32</td>\n",
       "      <td>66.46</td>\n",
       "      <td>23.22</td>\n",
       "      <td>15.61</td>\n",
       "      <td>黑龙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>15</td>\n",
       "      <td>18.78</td>\n",
       "      <td>60.32</td>\n",
       "      <td>20.90</td>\n",
       "      <td>15.13</td>\n",
       "      <td>山东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>12</td>\n",
       "      <td>19.24</td>\n",
       "      <td>61.96</td>\n",
       "      <td>18.79</td>\n",
       "      <td>15.01</td>\n",
       "      <td>安徽</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>18</td>\n",
       "      <td>19.52</td>\n",
       "      <td>60.60</td>\n",
       "      <td>19.88</td>\n",
       "      <td>14.81</td>\n",
       "      <td>湖南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2</td>\n",
       "      <td>13.47</td>\n",
       "      <td>64.87</td>\n",
       "      <td>21.66</td>\n",
       "      <td>14.75</td>\n",
       "      <td>天津</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>17</td>\n",
       "      <td>16.31</td>\n",
       "      <td>63.26</td>\n",
       "      <td>20.42</td>\n",
       "      <td>14.59</td>\n",
       "      <td>湖北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>3</td>\n",
       "      <td>20.22</td>\n",
       "      <td>59.92</td>\n",
       "      <td>19.85</td>\n",
       "      <td>13.92</td>\n",
       "      <td>河北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>16</td>\n",
       "      <td>23.14</td>\n",
       "      <td>58.79</td>\n",
       "      <td>18.08</td>\n",
       "      <td>13.49</td>\n",
       "      <td>河南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>27</td>\n",
       "      <td>17.33</td>\n",
       "      <td>63.46</td>\n",
       "      <td>19.20</td>\n",
       "      <td>13.32</td>\n",
       "      <td>陕西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>1</td>\n",
       "      <td>11.84</td>\n",
       "      <td>68.53</td>\n",
       "      <td>19.63</td>\n",
       "      <td>13.30</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>11</td>\n",
       "      <td>13.45</td>\n",
       "      <td>67.86</td>\n",
       "      <td>18.70</td>\n",
       "      <td>13.27</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>5</td>\n",
       "      <td>14.04</td>\n",
       "      <td>66.17</td>\n",
       "      <td>19.78</td>\n",
       "      <td>13.05</td>\n",
       "      <td>内蒙古</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>4</td>\n",
       "      <td>16.35</td>\n",
       "      <td>64.72</td>\n",
       "      <td>18.92</td>\n",
       "      <td>12.90</td>\n",
       "      <td>山西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>28</td>\n",
       "      <td>19.40</td>\n",
       "      <td>63.57</td>\n",
       "      <td>17.03</td>\n",
       "      <td>12.58</td>\n",
       "      <td>甘肃</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>20</td>\n",
       "      <td>23.63</td>\n",
       "      <td>59.69</td>\n",
       "      <td>16.69</td>\n",
       "      <td>12.20</td>\n",
       "      <td>广西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>14</td>\n",
       "      <td>21.96</td>\n",
       "      <td>61.17</td>\n",
       "      <td>16.87</td>\n",
       "      <td>11.89</td>\n",
       "      <td>江西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>24</td>\n",
       "      <td>23.97</td>\n",
       "      <td>60.65</td>\n",
       "      <td>15.38</td>\n",
       "      <td>11.56</td>\n",
       "      <td>贵州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>13</td>\n",
       "      <td>19.32</td>\n",
       "      <td>64.70</td>\n",
       "      <td>15.98</td>\n",
       "      <td>11.10</td>\n",
       "      <td>福建</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>19.57</td>\n",
       "      <td>65.52</td>\n",
       "      <td>14.91</td>\n",
       "      <td>10.75</td>\n",
       "      <td>云南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>21</td>\n",
       "      <td>19.97</td>\n",
       "      <td>65.38</td>\n",
       "      <td>14.65</td>\n",
       "      <td>10.43</td>\n",
       "      <td>海南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>30</td>\n",
       "      <td>20.38</td>\n",
       "      <td>66.09</td>\n",
       "      <td>13.52</td>\n",
       "      <td>9.62</td>\n",
       "      <td>宁夏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>29</td>\n",
       "      <td>20.81</td>\n",
       "      <td>67.04</td>\n",
       "      <td>12.14</td>\n",
       "      <td>8.68</td>\n",
       "      <td>青海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>19</td>\n",
       "      <td>18.85</td>\n",
       "      <td>68.80</td>\n",
       "      <td>12.35</td>\n",
       "      <td>8.58</td>\n",
       "      <td>广东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>31</td>\n",
       "      <td>22.46</td>\n",
       "      <td>66.26</td>\n",
       "      <td>11.28</td>\n",
       "      <td>7.76</td>\n",
       "      <td>新疆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>26</td>\n",
       "      <td>24.53</td>\n",
       "      <td>66.95</td>\n",
       "      <td>8.52</td>\n",
       "      <td>5.67</td>\n",
       "      <td>西藏</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Unnamed: 0  0-14岁比重(%)  15-59岁比重(%)  60岁及以上比重(%)  其中65岁及以上比重(%)   地区\n",
       "0            6       11.12        63.16        25.72          17.42   辽宁\n",
       "1           22       15.91        62.22        21.87          17.08   重庆\n",
       "2           23       16.10        62.19        21.71          16.93   四川\n",
       "3            9        9.80        66.82        23.38          16.28   上海\n",
       "4           10       15.21        62.95        21.84          16.20   江苏\n",
       "5            7       11.71        65.23        23.06          15.61   吉林\n",
       "6            8       10.32        66.46        23.22          15.61  黑龙江\n",
       "7           15       18.78        60.32        20.90          15.13   山东\n",
       "8           12       19.24        61.96        18.79          15.01   安徽\n",
       "9           18       19.52        60.60        19.88          14.81   湖南\n",
       "10           2       13.47        64.87        21.66          14.75   天津\n",
       "11          17       16.31        63.26        20.42          14.59   湖北\n",
       "12           3       20.22        59.92        19.85          13.92   河北\n",
       "13          16       23.14        58.79        18.08          13.49   河南\n",
       "14          27       17.33        63.46        19.20          13.32   陕西\n",
       "15           1       11.84        68.53        19.63          13.30   北京\n",
       "16          11       13.45        67.86        18.70          13.27   浙江\n",
       "17           5       14.04        66.17        19.78          13.05  内蒙古\n",
       "18           4       16.35        64.72        18.92          12.90   山西\n",
       "19          28       19.40        63.57        17.03          12.58   甘肃\n",
       "20          20       23.63        59.69        16.69          12.20   广西\n",
       "21          14       21.96        61.17        16.87          11.89   江西\n",
       "22          24       23.97        60.65        15.38          11.56   贵州\n",
       "23          13       19.32        64.70        15.98          11.10   福建\n",
       "24          25       19.57        65.52        14.91          10.75   云南\n",
       "25          21       19.97        65.38        14.65          10.43   海南\n",
       "26          30       20.38        66.09        13.52           9.62   宁夏\n",
       "27          29       20.81        67.04        12.14           8.68   青海\n",
       "28          19       18.85        68.80        12.35           8.58   广东\n",
       "29          31       22.46        66.26        11.28           7.76   新疆\n",
       "30          26       24.53        66.95         8.52           5.67   西藏"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删掉全国的数据\n",
    "age_region.drop(index=[0],inplace=True)\n",
    "# 排序\n",
    "age_region.sort_values(by='其中65岁及以上比重(%)',inplace=True,ascending=False)\n",
    "# 更新索引\n",
    "age_region.dropna().reset_index(drop=True)\n",
    "# age_region1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 提取前五个和后五个数据\n",
    "age_region1 = age_region.iloc[[0,1,2,3,4,26,27,28,29,30]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\1\\\\Desktop\\\\第七次人口普查数据\\\\html\\\\老龄化程度对比图.html'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "color_function = \"\"\"\n",
    "        function (params) {\n",
    "            if (params.value < 16) \n",
    "                return '#66CC99';\n",
    "            else return '#009999';\n",
    "        }\n",
    "        \"\"\"\n",
    "\n",
    "bar = (\n",
    "    Bar()\n",
    "    .add_xaxis(age_region1['地区'].tolist())      # x轴\n",
    "    .add_yaxis(series_name=\"65岁及以上人口占比\", y_axis=age_region1['其中65岁及以上比重(%)'].tolist(),itemstyle_opts=opts.ItemStyleOpts(color=JsCode(color_function)))\n",
    "\n",
    "#     .reversal_axis()   # xy轴交换\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='老龄化程度对比图',\n",
    "                                  subtitle='此表格选取各五个老龄化程度最重与最轻的数据，老龄化形成的原因是多方面的。\\n\\n①有年轻劳动力流失流入问题。\\n\\n②医疗水平提高，人类寿命普遍提高。\\n\\n③新中国建立后，生育潮爆发。\\n\\n④人们生育意愿不高等。', \n",
    "                                  title_textstyle_opts=opts.TextStyleOpts(), pos_left=\"50%\", pos_top=\"0\",\n",
    "                                  ),\n",
    "        legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"35%\", pos_right=\"0%\"),\n",
    "    )\n",
    "\n",
    ")\n",
    "\n",
    "\n",
    "line = (\n",
    "    Line()\n",
    "    .add_xaxis(age_region1['地区'].tolist())      # x轴\n",
    "    .add_yaxis(series_name=\"老龄化程度\", y_axis=age_region1['其中65岁及以上比重(%)'].tolist(),color=[\"#336699\"])\n",
    "    .set_series_opts(label_opts = opts.LabelOpts(is_show=False))\n",
    "    \n",
    ")\n",
    "\n",
    "bar.overlap(line).render(\"html/老龄化程度对比图.html\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 新生一代对比图_柱状图、折线图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>0-14岁比重(%)</th>\n",
       "      <th>15-59岁比重(%)</th>\n",
       "      <th>60岁及以上比重(%)</th>\n",
       "      <th>其中65岁及以上比重(%)</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>17.95</td>\n",
       "      <td>63.35</td>\n",
       "      <td>18.70</td>\n",
       "      <td>13.50</td>\n",
       "      <td>全国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>11.84</td>\n",
       "      <td>68.53</td>\n",
       "      <td>19.63</td>\n",
       "      <td>13.30</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>13.47</td>\n",
       "      <td>64.87</td>\n",
       "      <td>21.66</td>\n",
       "      <td>14.75</td>\n",
       "      <td>天津</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>20.22</td>\n",
       "      <td>59.92</td>\n",
       "      <td>19.85</td>\n",
       "      <td>13.92</td>\n",
       "      <td>河北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>16.35</td>\n",
       "      <td>64.72</td>\n",
       "      <td>18.92</td>\n",
       "      <td>12.90</td>\n",
       "      <td>山西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>14.04</td>\n",
       "      <td>66.17</td>\n",
       "      <td>19.78</td>\n",
       "      <td>13.05</td>\n",
       "      <td>内蒙古</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>11.12</td>\n",
       "      <td>63.16</td>\n",
       "      <td>25.72</td>\n",
       "      <td>17.42</td>\n",
       "      <td>辽宁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>11.71</td>\n",
       "      <td>65.23</td>\n",
       "      <td>23.06</td>\n",
       "      <td>15.61</td>\n",
       "      <td>吉林</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>10.32</td>\n",
       "      <td>66.46</td>\n",
       "      <td>23.22</td>\n",
       "      <td>15.61</td>\n",
       "      <td>黑龙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>9.80</td>\n",
       "      <td>66.82</td>\n",
       "      <td>23.38</td>\n",
       "      <td>16.28</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>15.21</td>\n",
       "      <td>62.95</td>\n",
       "      <td>21.84</td>\n",
       "      <td>16.20</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>11</td>\n",
       "      <td>13.45</td>\n",
       "      <td>67.86</td>\n",
       "      <td>18.70</td>\n",
       "      <td>13.27</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>12</td>\n",
       "      <td>19.24</td>\n",
       "      <td>61.96</td>\n",
       "      <td>18.79</td>\n",
       "      <td>15.01</td>\n",
       "      <td>安徽</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>13</td>\n",
       "      <td>19.32</td>\n",
       "      <td>64.70</td>\n",
       "      <td>15.98</td>\n",
       "      <td>11.10</td>\n",
       "      <td>福建</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>14</td>\n",
       "      <td>21.96</td>\n",
       "      <td>61.17</td>\n",
       "      <td>16.87</td>\n",
       "      <td>11.89</td>\n",
       "      <td>江西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>15</td>\n",
       "      <td>18.78</td>\n",
       "      <td>60.32</td>\n",
       "      <td>20.90</td>\n",
       "      <td>15.13</td>\n",
       "      <td>山东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>16</td>\n",
       "      <td>23.14</td>\n",
       "      <td>58.79</td>\n",
       "      <td>18.08</td>\n",
       "      <td>13.49</td>\n",
       "      <td>河南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>17</td>\n",
       "      <td>16.31</td>\n",
       "      <td>63.26</td>\n",
       "      <td>20.42</td>\n",
       "      <td>14.59</td>\n",
       "      <td>湖北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>18</td>\n",
       "      <td>19.52</td>\n",
       "      <td>60.60</td>\n",
       "      <td>19.88</td>\n",
       "      <td>14.81</td>\n",
       "      <td>湖南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>19</td>\n",
       "      <td>18.85</td>\n",
       "      <td>68.80</td>\n",
       "      <td>12.35</td>\n",
       "      <td>8.58</td>\n",
       "      <td>广东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>20</td>\n",
       "      <td>23.63</td>\n",
       "      <td>59.69</td>\n",
       "      <td>16.69</td>\n",
       "      <td>12.20</td>\n",
       "      <td>广西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>21</td>\n",
       "      <td>19.97</td>\n",
       "      <td>65.38</td>\n",
       "      <td>14.65</td>\n",
       "      <td>10.43</td>\n",
       "      <td>海南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>22</td>\n",
       "      <td>15.91</td>\n",
       "      <td>62.22</td>\n",
       "      <td>21.87</td>\n",
       "      <td>17.08</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>23</td>\n",
       "      <td>16.10</td>\n",
       "      <td>62.19</td>\n",
       "      <td>21.71</td>\n",
       "      <td>16.93</td>\n",
       "      <td>四川</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>24</td>\n",
       "      <td>23.97</td>\n",
       "      <td>60.65</td>\n",
       "      <td>15.38</td>\n",
       "      <td>11.56</td>\n",
       "      <td>贵州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>25</td>\n",
       "      <td>19.57</td>\n",
       "      <td>65.52</td>\n",
       "      <td>14.91</td>\n",
       "      <td>10.75</td>\n",
       "      <td>云南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>26</td>\n",
       "      <td>24.53</td>\n",
       "      <td>66.95</td>\n",
       "      <td>8.52</td>\n",
       "      <td>5.67</td>\n",
       "      <td>西藏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>27</td>\n",
       "      <td>17.33</td>\n",
       "      <td>63.46</td>\n",
       "      <td>19.20</td>\n",
       "      <td>13.32</td>\n",
       "      <td>陕西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>28</td>\n",
       "      <td>19.40</td>\n",
       "      <td>63.57</td>\n",
       "      <td>17.03</td>\n",
       "      <td>12.58</td>\n",
       "      <td>甘肃</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>29</td>\n",
       "      <td>20.81</td>\n",
       "      <td>67.04</td>\n",
       "      <td>12.14</td>\n",
       "      <td>8.68</td>\n",
       "      <td>青海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>30</td>\n",
       "      <td>20.38</td>\n",
       "      <td>66.09</td>\n",
       "      <td>13.52</td>\n",
       "      <td>9.62</td>\n",
       "      <td>宁夏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>31</td>\n",
       "      <td>22.46</td>\n",
       "      <td>66.26</td>\n",
       "      <td>11.28</td>\n",
       "      <td>7.76</td>\n",
       "      <td>新疆</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Unnamed: 0  0-14岁比重(%)  15-59岁比重(%)  60岁及以上比重(%)  其中65岁及以上比重(%)   地区\n",
       "0            0       17.95        63.35        18.70          13.50   全国\n",
       "1            1       11.84        68.53        19.63          13.30   北京\n",
       "2            2       13.47        64.87        21.66          14.75   天津\n",
       "3            3       20.22        59.92        19.85          13.92   河北\n",
       "4            4       16.35        64.72        18.92          12.90   山西\n",
       "5            5       14.04        66.17        19.78          13.05  内蒙古\n",
       "6            6       11.12        63.16        25.72          17.42   辽宁\n",
       "7            7       11.71        65.23        23.06          15.61   吉林\n",
       "8            8       10.32        66.46        23.22          15.61  黑龙江\n",
       "9            9        9.80        66.82        23.38          16.28   上海\n",
       "10          10       15.21        62.95        21.84          16.20   江苏\n",
       "11          11       13.45        67.86        18.70          13.27   浙江\n",
       "12          12       19.24        61.96        18.79          15.01   安徽\n",
       "13          13       19.32        64.70        15.98          11.10   福建\n",
       "14          14       21.96        61.17        16.87          11.89   江西\n",
       "15          15       18.78        60.32        20.90          15.13   山东\n",
       "16          16       23.14        58.79        18.08          13.49   河南\n",
       "17          17       16.31        63.26        20.42          14.59   湖北\n",
       "18          18       19.52        60.60        19.88          14.81   湖南\n",
       "19          19       18.85        68.80        12.35           8.58   广东\n",
       "20          20       23.63        59.69        16.69          12.20   广西\n",
       "21          21       19.97        65.38        14.65          10.43   海南\n",
       "22          22       15.91        62.22        21.87          17.08   重庆\n",
       "23          23       16.10        62.19        21.71          16.93   四川\n",
       "24          24       23.97        60.65        15.38          11.56   贵州\n",
       "25          25       19.57        65.52        14.91          10.75   云南\n",
       "26          26       24.53        66.95         8.52           5.67   西藏\n",
       "27          27       17.33        63.46        19.20          13.32   陕西\n",
       "28          28       19.40        63.57        17.03          12.58   甘肃\n",
       "29          29       20.81        67.04        12.14           8.68   青海\n",
       "30          30       20.38        66.09        13.52           9.62   宁夏\n",
       "31          31       22.46        66.26        11.28           7.76   新疆"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_region = pd.read_csv('data/各地区人口年龄构成数据.csv')\n",
    "age_region"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>0-14岁比重(%)</th>\n",
       "      <th>15-59岁比重(%)</th>\n",
       "      <th>60岁及以上比重(%)</th>\n",
       "      <th>其中65岁及以上比重(%)</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>26</td>\n",
       "      <td>24.53</td>\n",
       "      <td>66.95</td>\n",
       "      <td>8.52</td>\n",
       "      <td>5.67</td>\n",
       "      <td>西藏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>24</td>\n",
       "      <td>23.97</td>\n",
       "      <td>60.65</td>\n",
       "      <td>15.38</td>\n",
       "      <td>11.56</td>\n",
       "      <td>贵州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20</td>\n",
       "      <td>23.63</td>\n",
       "      <td>59.69</td>\n",
       "      <td>16.69</td>\n",
       "      <td>12.20</td>\n",
       "      <td>广西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>16</td>\n",
       "      <td>23.14</td>\n",
       "      <td>58.79</td>\n",
       "      <td>18.08</td>\n",
       "      <td>13.49</td>\n",
       "      <td>河南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>31</td>\n",
       "      <td>22.46</td>\n",
       "      <td>66.26</td>\n",
       "      <td>11.28</td>\n",
       "      <td>7.76</td>\n",
       "      <td>新疆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>14</td>\n",
       "      <td>21.96</td>\n",
       "      <td>61.17</td>\n",
       "      <td>16.87</td>\n",
       "      <td>11.89</td>\n",
       "      <td>江西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>29</td>\n",
       "      <td>20.81</td>\n",
       "      <td>67.04</td>\n",
       "      <td>12.14</td>\n",
       "      <td>8.68</td>\n",
       "      <td>青海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>30</td>\n",
       "      <td>20.38</td>\n",
       "      <td>66.09</td>\n",
       "      <td>13.52</td>\n",
       "      <td>9.62</td>\n",
       "      <td>宁夏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>3</td>\n",
       "      <td>20.22</td>\n",
       "      <td>59.92</td>\n",
       "      <td>19.85</td>\n",
       "      <td>13.92</td>\n",
       "      <td>河北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>21</td>\n",
       "      <td>19.97</td>\n",
       "      <td>65.38</td>\n",
       "      <td>14.65</td>\n",
       "      <td>10.43</td>\n",
       "      <td>海南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>25</td>\n",
       "      <td>19.57</td>\n",
       "      <td>65.52</td>\n",
       "      <td>14.91</td>\n",
       "      <td>10.75</td>\n",
       "      <td>云南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>18</td>\n",
       "      <td>19.52</td>\n",
       "      <td>60.60</td>\n",
       "      <td>19.88</td>\n",
       "      <td>14.81</td>\n",
       "      <td>湖南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>28</td>\n",
       "      <td>19.40</td>\n",
       "      <td>63.57</td>\n",
       "      <td>17.03</td>\n",
       "      <td>12.58</td>\n",
       "      <td>甘肃</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>13</td>\n",
       "      <td>19.32</td>\n",
       "      <td>64.70</td>\n",
       "      <td>15.98</td>\n",
       "      <td>11.10</td>\n",
       "      <td>福建</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>12</td>\n",
       "      <td>19.24</td>\n",
       "      <td>61.96</td>\n",
       "      <td>18.79</td>\n",
       "      <td>15.01</td>\n",
       "      <td>安徽</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>19</td>\n",
       "      <td>18.85</td>\n",
       "      <td>68.80</td>\n",
       "      <td>12.35</td>\n",
       "      <td>8.58</td>\n",
       "      <td>广东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>15</td>\n",
       "      <td>18.78</td>\n",
       "      <td>60.32</td>\n",
       "      <td>20.90</td>\n",
       "      <td>15.13</td>\n",
       "      <td>山东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>27</td>\n",
       "      <td>17.33</td>\n",
       "      <td>63.46</td>\n",
       "      <td>19.20</td>\n",
       "      <td>13.32</td>\n",
       "      <td>陕西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>4</td>\n",
       "      <td>16.35</td>\n",
       "      <td>64.72</td>\n",
       "      <td>18.92</td>\n",
       "      <td>12.90</td>\n",
       "      <td>山西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>17</td>\n",
       "      <td>16.31</td>\n",
       "      <td>63.26</td>\n",
       "      <td>20.42</td>\n",
       "      <td>14.59</td>\n",
       "      <td>湖北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>23</td>\n",
       "      <td>16.10</td>\n",
       "      <td>62.19</td>\n",
       "      <td>21.71</td>\n",
       "      <td>16.93</td>\n",
       "      <td>四川</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>15.91</td>\n",
       "      <td>62.22</td>\n",
       "      <td>21.87</td>\n",
       "      <td>17.08</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>10</td>\n",
       "      <td>15.21</td>\n",
       "      <td>62.95</td>\n",
       "      <td>21.84</td>\n",
       "      <td>16.20</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>5</td>\n",
       "      <td>14.04</td>\n",
       "      <td>66.17</td>\n",
       "      <td>19.78</td>\n",
       "      <td>13.05</td>\n",
       "      <td>内蒙古</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2</td>\n",
       "      <td>13.47</td>\n",
       "      <td>64.87</td>\n",
       "      <td>21.66</td>\n",
       "      <td>14.75</td>\n",
       "      <td>天津</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>11</td>\n",
       "      <td>13.45</td>\n",
       "      <td>67.86</td>\n",
       "      <td>18.70</td>\n",
       "      <td>13.27</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>1</td>\n",
       "      <td>11.84</td>\n",
       "      <td>68.53</td>\n",
       "      <td>19.63</td>\n",
       "      <td>13.30</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>7</td>\n",
       "      <td>11.71</td>\n",
       "      <td>65.23</td>\n",
       "      <td>23.06</td>\n",
       "      <td>15.61</td>\n",
       "      <td>吉林</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>6</td>\n",
       "      <td>11.12</td>\n",
       "      <td>63.16</td>\n",
       "      <td>25.72</td>\n",
       "      <td>17.42</td>\n",
       "      <td>辽宁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>8</td>\n",
       "      <td>10.32</td>\n",
       "      <td>66.46</td>\n",
       "      <td>23.22</td>\n",
       "      <td>15.61</td>\n",
       "      <td>黑龙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>9</td>\n",
       "      <td>9.80</td>\n",
       "      <td>66.82</td>\n",
       "      <td>23.38</td>\n",
       "      <td>16.28</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Unnamed: 0  0-14岁比重(%)  15-59岁比重(%)  60岁及以上比重(%)  其中65岁及以上比重(%)   地区\n",
       "0           26       24.53        66.95         8.52           5.67   西藏\n",
       "1           24       23.97        60.65        15.38          11.56   贵州\n",
       "2           20       23.63        59.69        16.69          12.20   广西\n",
       "3           16       23.14        58.79        18.08          13.49   河南\n",
       "4           31       22.46        66.26        11.28           7.76   新疆\n",
       "5           14       21.96        61.17        16.87          11.89   江西\n",
       "6           29       20.81        67.04        12.14           8.68   青海\n",
       "7           30       20.38        66.09        13.52           9.62   宁夏\n",
       "8            3       20.22        59.92        19.85          13.92   河北\n",
       "9           21       19.97        65.38        14.65          10.43   海南\n",
       "10          25       19.57        65.52        14.91          10.75   云南\n",
       "11          18       19.52        60.60        19.88          14.81   湖南\n",
       "12          28       19.40        63.57        17.03          12.58   甘肃\n",
       "13          13       19.32        64.70        15.98          11.10   福建\n",
       "14          12       19.24        61.96        18.79          15.01   安徽\n",
       "15          19       18.85        68.80        12.35           8.58   广东\n",
       "16          15       18.78        60.32        20.90          15.13   山东\n",
       "17          27       17.33        63.46        19.20          13.32   陕西\n",
       "18           4       16.35        64.72        18.92          12.90   山西\n",
       "19          17       16.31        63.26        20.42          14.59   湖北\n",
       "20          23       16.10        62.19        21.71          16.93   四川\n",
       "21          22       15.91        62.22        21.87          17.08   重庆\n",
       "22          10       15.21        62.95        21.84          16.20   江苏\n",
       "23           5       14.04        66.17        19.78          13.05  内蒙古\n",
       "24           2       13.47        64.87        21.66          14.75   天津\n",
       "25          11       13.45        67.86        18.70          13.27   浙江\n",
       "26           1       11.84        68.53        19.63          13.30   北京\n",
       "27           7       11.71        65.23        23.06          15.61   吉林\n",
       "28           6       11.12        63.16        25.72          17.42   辽宁\n",
       "29           8       10.32        66.46        23.22          15.61  黑龙江\n",
       "30           9        9.80        66.82        23.38          16.28   上海"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删掉全国的数据\n",
    "age_region.drop(index=[0],inplace=True)\n",
    "# 排序\n",
    "age_region.sort_values(by='0-14岁比重(%)',inplace=True,ascending=False)\n",
    "# 更新索引\n",
    "age_region.dropna().reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 提取前五个和后五个数据\n",
    "age_region2 = age_region.iloc[[0,1,2,3,4,26,27,28,29,30]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\1\\\\Desktop\\\\第七次人口普查数据\\\\html\\\\地区新生比重对比图.html'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "color_function = \"\"\"\n",
    "        function (params) {\n",
    "            if (params.value < 20) \n",
    "                return '#99CC99';\n",
    "            else return '#FFCC99';\n",
    "        }\n",
    "        \"\"\"\n",
    "\n",
    "bar = (\n",
    "    Bar()\n",
    "    .add_xaxis(age_region2['地区'].tolist())      # x轴\n",
    "    .add_yaxis(series_name=\"0-14岁人口占比\", y_axis=age_region2['0-14岁比重(%)'].tolist(),itemstyle_opts=opts.ItemStyleOpts(color=JsCode(color_function)))\n",
    "\n",
    "#     .reversal_axis()   # xy轴交换\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='地区新生比重对比图',\n",
    "                                  subtitle='此表格选取各地区0-14岁人口占比最大与最小的数据。\\n\\n由图表看出，我国经济发达区域，近十四年新生人口占比较低，一方面有计划生育政策的原因，同时人们生育意愿不高等原因存在。', \n",
    "                                  title_textstyle_opts=opts.TextStyleOpts(), pos_left=\"50%\", pos_top=\"0\",\n",
    "                                  ),\n",
    "        legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"35%\", pos_right=\"0%\"),\n",
    "    )\n",
    "\n",
    ")\n",
    "\n",
    "\n",
    "line = (\n",
    "    Line()\n",
    "    .add_xaxis(age_region2['地区'].tolist())      # x轴\n",
    "    .add_yaxis(series_name=\"0-14岁人口占比\", y_axis=age_region2['0-14岁比重(%)'].tolist(),color=[\"#99CC99\"])\n",
    "    .set_series_opts(label_opts = opts.LabelOpts(is_show=False))\n",
    "    \n",
    ")\n",
    "\n",
    "bar.overlap(line).render(\"html/地区新生比重对比图.html\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 各地区15岁及以上人口平均受教育年限对比图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>2020年</th>\n",
       "      <th>2010年</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>9.91</td>\n",
       "      <td>9.08</td>\n",
       "      <td>全国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>12.64</td>\n",
       "      <td>11.71</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>11.29</td>\n",
       "      <td>10.38</td>\n",
       "      <td>天津</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>9.84</td>\n",
       "      <td>9.12</td>\n",
       "      <td>河北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>10.45</td>\n",
       "      <td>9.52</td>\n",
       "      <td>山西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>10.08</td>\n",
       "      <td>9.22</td>\n",
       "      <td>内蒙古</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>10.34</td>\n",
       "      <td>9.67</td>\n",
       "      <td>辽宁</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>10.17</td>\n",
       "      <td>9.49</td>\n",
       "      <td>吉林</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>9.93</td>\n",
       "      <td>9.36</td>\n",
       "      <td>黑龙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>11.81</td>\n",
       "      <td>10.73</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>10.21</td>\n",
       "      <td>9.32</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>11</td>\n",
       "      <td>9.79</td>\n",
       "      <td>8.79</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>12</td>\n",
       "      <td>9.35</td>\n",
       "      <td>8.28</td>\n",
       "      <td>安徽</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>13</td>\n",
       "      <td>9.66</td>\n",
       "      <td>9.02</td>\n",
       "      <td>福建</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>14</td>\n",
       "      <td>9.70</td>\n",
       "      <td>8.86</td>\n",
       "      <td>江西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>15</td>\n",
       "      <td>9.75</td>\n",
       "      <td>8.97</td>\n",
       "      <td>山东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>16</td>\n",
       "      <td>9.79</td>\n",
       "      <td>8.95</td>\n",
       "      <td>河南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>17</td>\n",
       "      <td>10.02</td>\n",
       "      <td>9.20</td>\n",
       "      <td>湖北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>18</td>\n",
       "      <td>9.88</td>\n",
       "      <td>9.16</td>\n",
       "      <td>湖南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>19</td>\n",
       "      <td>10.38</td>\n",
       "      <td>9.55</td>\n",
       "      <td>广东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>20</td>\n",
       "      <td>9.54</td>\n",
       "      <td>8.76</td>\n",
       "      <td>广西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>21</td>\n",
       "      <td>10.10</td>\n",
       "      <td>9.22</td>\n",
       "      <td>海南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>22</td>\n",
       "      <td>9.80</td>\n",
       "      <td>8.75</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>23</td>\n",
       "      <td>9.24</td>\n",
       "      <td>8.35</td>\n",
       "      <td>四川</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>24</td>\n",
       "      <td>8.75</td>\n",
       "      <td>7.65</td>\n",
       "      <td>贵州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>25</td>\n",
       "      <td>8.82</td>\n",
       "      <td>7.76</td>\n",
       "      <td>云南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>26</td>\n",
       "      <td>6.75</td>\n",
       "      <td>5.25</td>\n",
       "      <td>西藏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>27</td>\n",
       "      <td>10.26</td>\n",
       "      <td>9.36</td>\n",
       "      <td>陕西</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>28</td>\n",
       "      <td>9.13</td>\n",
       "      <td>8.19</td>\n",
       "      <td>甘肃</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>29</td>\n",
       "      <td>8.85</td>\n",
       "      <td>7.85</td>\n",
       "      <td>青海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>30</td>\n",
       "      <td>9.81</td>\n",
       "      <td>8.82</td>\n",
       "      <td>宁夏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>31</td>\n",
       "      <td>10.11</td>\n",
       "      <td>9.27</td>\n",
       "      <td>新疆</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Unnamed: 0  2020年  2010年   地区\n",
       "0            0   9.91   9.08   全国\n",
       "1            1  12.64  11.71   北京\n",
       "2            2  11.29  10.38   天津\n",
       "3            3   9.84   9.12   河北\n",
       "4            4  10.45   9.52   山西\n",
       "5            5  10.08   9.22  内蒙古\n",
       "6            6  10.34   9.67   辽宁\n",
       "7            7  10.17   9.49   吉林\n",
       "8            8   9.93   9.36  黑龙江\n",
       "9            9  11.81  10.73   上海\n",
       "10          10  10.21   9.32   江苏\n",
       "11          11   9.79   8.79   浙江\n",
       "12          12   9.35   8.28   安徽\n",
       "13          13   9.66   9.02   福建\n",
       "14          14   9.70   8.86   江西\n",
       "15          15   9.75   8.97   山东\n",
       "16          16   9.79   8.95   河南\n",
       "17          17  10.02   9.20   湖北\n",
       "18          18   9.88   9.16   湖南\n",
       "19          19  10.38   9.55   广东\n",
       "20          20   9.54   8.76   广西\n",
       "21          21  10.10   9.22   海南\n",
       "22          22   9.80   8.75   重庆\n",
       "23          23   9.24   8.35   四川\n",
       "24          24   8.75   7.65   贵州\n",
       "25          25   8.82   7.76   云南\n",
       "26          26   6.75   5.25   西藏\n",
       "27          27  10.26   9.36   陕西\n",
       "28          28   9.13   8.19   甘肃\n",
       "29          29   8.85   7.85   青海\n",
       "30          30   9.81   8.82   宁夏\n",
       "31          31  10.11   9.27   新疆"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "education_year = pd.read_csv('data/各地区15岁及以上人口平均受教育年限.csv')\n",
    "education_year"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "b = (\n",
    "    Bar(\n",
    "#         init_opts=opts.InitOpts(           # 初始配置项\n",
    "#             theme=ThemeType.MACARONS,\n",
    "#             animation_opts=opts.AnimationOpts(\n",
    "#                 animation_delay=1000, animation_easing=\"cubicOut\"   # 初始动画延迟和缓动效果\n",
    "#             ))\n",
    "        )\n",
    "    # 选取表格中前五个数据\n",
    "    .add_xaxis(xaxis_data=education_year.head()['地区'].tolist())      # x轴\n",
    "    .add_yaxis(series_name=\"2010年\", y_axis=education_year.head()['2010年'].tolist(),color=[\"#336699\"])       # y轴\n",
    "    .add_yaxis(series_name=\"2020年\", y_axis=education_year.head()['2020年'].tolist(),color=[\"#99CC33\"])       # y轴\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title='15岁及以上人口平均受教育年限对比图',\n",
    "                                  subtitle='此表格选取前五个数据，15岁及以上人口平均受教育年限都在增长。 \\n\\n表明了我国人们越来越重视教育，科教兴国战略实施有效，民族是非常有希望的。', \n",
    "                                  title_textstyle_opts=opts.TextStyleOpts(), pos_left=\"center\", pos_top=\"0\",\n",
    "                                  ),\n",
    "        legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"35%\", pos_right=\"0%\"),\n",
    "        xaxis_opts=opts.AxisOpts(name='地区', axislabel_opts=opts.LabelOpts(rotate=0)),  # 设置x名称和Label rotate解决标签名字过长使用\n",
    "        yaxis_opts=opts.AxisOpts(name='15岁及以上人口平均受教育年限'),\n",
    "\n",
    "    )\n",
    "    .render(\"html/教育年限对比.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "302.975px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
